const tokens = {
  admin: {
    token: "admin-token",
  },
  editor: {
    token: "editor-token",
  },
};

/* {
  name: "Home",
  title: "首页",
  children: [{ name: "ShipAgencyHome" }],
},
{
  name: "Customer",
  title: "业务中心",
  children: [
    // { name: "CustomerProfile", title: "客户档案1" },
    { name: "ShipBg" },
  ],
}, */
const users = {
  "admin-token": {
    btnrouters: [], // 按钮权限
    routers: [], // 用户需要访问的路由信息
    roles: [{ name: "福州中远海运船务代理有限公司莆田分公司", code: "0013" }], // 当前用户的角色
    avatar:
      "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif", // 用户的头像
    name: "何佳奇", // 用户名称
  },
  "editor-token": {
    roles: ["editor"],
    introduction: "I am an editor",
    avatar:
      "https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif",
    name: "Normal Editor",
  },
};

module.exports = [
  // user login
  {
    url: "/vue-admin-template/user/login",
    type: "post",
    response: (config) => {
      const { username } = config.body;
      const token = tokens[username];

      // mock error
      if (!token) {
        return {
          code: 60204,
          message: "Account and password are incorrect.",
        };
      }

      return {
        code: 20000,
        data: token,
      };
    },
  },

  // get user info
  {
    url: "/vue-admin-template/user/info.*",
    type: "get",
    response: (config) => {
      const { token } = config.query;
      const info = users[token];
      // mock error
      if (!info) {
        return {
          code: 50008,
          message: "Login failed, unable to get user details.",
        };
      }

      return {
        code: 20000,
        data: info,
      };
    },
  },

  // user logout
  {
    url: "/vue-admin-template/user/logout",
    type: "post",
    response: (_) => {
      return {
        code: 20000,
        data: "success",
      };
    },
  },
];
